package com.test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LoginAction extends Action {
	private LoginService loginService;

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm arg1, HttpServletRequest request, HttpServletResponse response) throws Exception {
		Users u = new Users();
		u.setName(request.getParameter("name"));
		System.out.println("u.getName():"+u.getName());
		u.setPassword(request.getParameter("password"));
		boolean flag = loginService.isLogin(u);
		ActionForward af ;
		if(flag){
			af = mapping.findForward("success");
		}else{
			af = mapping.findForward("fail");
		}
		// TODO Auto-generated method stub
		return af;
	}
}
